<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <link href="../assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link href="../assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="../assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css"/>
    <link href="../assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="../assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet"
          type="text/css"/>


    <link href="../assets/global/plugins/select2/css/select2.min.css" rel="stylesheet" type="text/css"/>
    <link href="../assets/global/plugins/select2/css/select2-bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="../assets/global/plugins/bootstrap-touchspin/bootstrap.touchspin.css" rel="stylesheet" type="text/css"/>
    <link href="../assets/global/plugins/bootstrap-select/css/bootstrap-select.css" rel="stylesheet" type="text/css"/>
    <link href="../assets/global/plugins/jquery-multi-select/css/multi-select.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="../assets/global/plugins/doublebox/css/doublebox-bootstrap.css"/>

    <link href="../assets/global/css/components.min.css" rel="stylesheet" id="style_components" type="text/css"/>
    <link href="../assets/global/css/plugins.min.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="../assets/global/plugins/layui/css/layui.css"/>
    <link rel="stylesheet" href="../assets/custom/css/changeother.css"/>
</head>
<body>
<div class="contentPadding display_none">
    <div class="form-group clearfix addTimeBox display_none">
        <div class="col-xs-offset-11">
            <a href="javascript:;" class="addTime" style="margin-left: -35px;color: #20c1dc;"><i class="icon-plus"></i> 添加</a></label>
        </div>
    </div>
    <div class="dispatchTime">
        <div class="">
            <h3 class="col-xs-offset-1">调度时间 <span class="chineseCount">一</span> <span class="newOneTime">（新增）</span></h3>
        </div>
        <form class="form-body myForm">
            <div class="form-group clearfix runTimeType">
                <div class="row">
                    <span class="col-xs-2 col-xs-offset-1 label_on_l">调度类型：</span>
                    <div class="col-xs-6 ">
                        <select class="bs-select form-control" name="free">
                            <option>按时间间隔</option>
                            <option>按天</option>
                            <option>按周</option>
                            <option>按月</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="timeType  timeInterval">
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">以秒计算的间隔：</span>
                        <div class="col-xs-8">
                            <input class="touchspin_3" required  type="text" value="" name="demo_vertical"  max="59"></div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">以分计算的间隔：</span>
                        <div class="col-xs-8">
                            <input class="touchspin_3" required type="text" value="" name="demo_vertica2" max="59"></div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">运行时间段：</span>
                       <!-- <div class="col-xs-8">
                            <input type="text" class="time1" name="timeStart" oninput="" onporpertychange="">
                            <span>-&#45;&#45;&ndash;&gt;</span>
                            <input type="text" class="time2" name="timeEnd" oninput="" onporpertychange="">
                        </div>-->

                        <div class="col-xs-3">
                            <input type="text" class="time1 widthFull timeStart" name="timeStart" oninput="" onporpertychange="">
                        </div>

                        <div class="fl">
                            <span class="label_on_l">-----></span>
                        </div>

                        <div class="col-xs-3">
                            <input type="text" class="time2 widthFull" name="timeEnd" oninput="" onporpertychange="">
                        </div>

                    </div>
                </div>
            </div>

            <div class="timeType   timeEveryday display_none">
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">时间：</span>
                        <div class="col-xs-8">
                            <div class="col-xs-5 paddingZero">
                                <input class="touchspin_2 " type="text" value="" name="demo_vertical3" required max="23">
                            </div>
                            <span class="label_on_time">时</span>
                            <div class="col-xs-5 col-xs-offset-1 paddingZero">
                                <input class="touchspin_3 col-xs-6" type="text" value="" name="demo_vertical4" required max="59">
                            </div>
                            <span class="label_on_time">分</span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="timeType   timeWeekly display_none">
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">星期：</span>
                        <div class="col-xs-6 toggle_form_show">
                            <select class="bs-select form-control" name="free">
                                <option>星期天</option>
                                <option>星期一</option>
                                <option>星期二</option>
                                <option>星期三</option>
                                <option>星期四</option>
                                <option>星期五</option>
                                <option>星期六</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">时间：</span>
                        <div class="col-xs-8">
                            <div class="col-xs-5 paddingZero">
                                <input class="touchspin_2 " type="text" value="" name="demo_vertical5" required max="23">
                            </div>
                            <span class="label_on_time">时</span>
                            <div class="col-xs-5 col-xs-offset-1 paddingZero">
                                <input class="touchspin_3 col-xs-6" type="text" value="" name="demo_vertical6" required max="59">
                            </div>
                            <span class="label_on_time">分</span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="timeType  timeMonth display_none">
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">每月第几天：</span>
                        <div class="col-xs-8">
                            <input class="touchspin_1" type="text" value="" name="demo_vertical7" required min="1" max="31"></div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">时间：</span>
                        <div class="col-xs-8">
                            <div class="col-xs-5 paddingZero">
                                <input class="touchspin_2 " type="text" value="" name="demo_vertical1" required max="23">
                            </div>
                            <span class="label_on_time">时</span>
                            <div class="col-xs-5 col-xs-offset-1 paddingZero">
                                <input class="touchspin_3 col-xs-6" type="text" value="" name="demo_vertical2" required max="59">
                            </div>
                            <span class="label_on_time">分</span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group clearfix">
                <div class="col-xs-offset-7 col-xs-4">
                    <button class="btn default  display_none fr cancelTime" style="margin-left: 10px;width: 80px;">删除</button>
                    <button class="btn blue-hoki fr saveTime" data-saveSort="0" style="width: 80px;">保存</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script src="../assets/global/plugins/jquery.min.js" type="text/javascript"></script>
<script src="../assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>

<script src="../assets/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js" type="text/javascript"></script>
<script src="../assets/global/plugins/bootstrap-select/js/bootstrap-select.min.js" type="text/javascript"></script>
<script src="../assets/global/plugins/jquery-multi-select/js/jquery.multi-select.js" type="text/javascript"></script>
<script src="../assets/global/plugins/select2/js/select2.full.min.js" type="text/javascript"></script>
<!-- END CORE PLUGINS -->
<!-- BEGIN THEME GLOBAL SCRIPTS -->
<script src="../assets/global/plugins/fuelux/js/spinner.min.js" type="text/javascript"></script>
<script src="../assets/global/plugins/bootstrap-touchspin/bootstrap.touchspin.js" type="text/javascript"></script>

<script src="../assets/global/scripts/app.min.js" type="text/javascript"></script>

<script src="../assets/pages/scripts/components-bootstrap-touchspin.min.js" type="text/javascript"></script>
<script src="../assets/pages/scripts/components-multi-select.min.js" type="text/javascript"></script>
<script src="../assets/pages/scripts/components-select2.min.js" type="text/javascript"></script>

<script src="../assets/global/plugins/layui/layui.all.js"></script>
<script src="../assets/pages/scripts/jquery.validate.js"></script>

<script>

    $(function(){

        //添加调度时间的模板
        var dispatchTimeHtml =
            ` <div class="dispatchTime">
        <div class="">
            <h3 class="col-xs-offset-1">调度时间<span class="chineseCount">一</span></h3>
        </div>
        <form class="form-body myForm">
            <div class="form-group clearfix runTimeType">
                <div class="row">
                    <span class="col-xs-2 col-xs-offset-1 label_on_l">调度类型：</span>
                    <div class="col-xs-6 ">
                        <select class="bs-select form-control" name="free">
                            <option>按时间间隔</option>
                            <option>按天</option>
                            <option>按周</option>
                            <option>按月</option>
                        </select>
                    </div>
                </div>
            </div>
              <div class="timeType  timeInterval">
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">以秒计算的间隔：</span>
                        <div class="col-xs-8">
                            <input class="touchspin_3" required  type="text" value="" name="demo_vertical812"  max="59"></div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">以分计算的间隔：</span>
                        <div class="col-xs-8">
                            <input class="touchspin_3" required type="text" value="" name="demo_vertical88" max="59"></div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">运行时间段：</span>
                       <!-- <div class="col-xs-8">
                            <input type="text" class="time1" name="timeStart" oninput="" onporpertychange="">
                            <span>-&#45;&#45;&ndash;&gt;</span>
                            <input type="text" class="time2" name="timeEnd" oninput="" onporpertychange="">
                        </div>-->

                        <div class="col-xs-3">
                            <input type="text" class="time1 widthFull" name="timeStart" oninput="" onporpertychange="">
                        </div>

                        <div class="fl">
                            <span class="label_on_l">-----></span>
                        </div>

                        <div class="col-xs-3">
                            <input type="text" class="time2 widthFull" name="timeEnd" oninput="" onporpertychange="">
                        </div>

                    </div>
                </div>
            </div>

            <div class="timeType   timeEveryday display_none">
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">时间：</span>
                        <div class="col-xs-8">
                            <div class="col-xs-5 paddingZero">
                                <input class="touchspin_2 " type="text" value="" name="demo_vertical123" required max="23">
                            </div>
                            <span class="label_on_time">时</span>
                            <div class="col-xs-5 col-xs-offset-1 paddingZero">
                                <input class="touchspin_3 col-xs-6" type="text" value="" name="demo_vertical456" required max="59">
                            </div>
                            <span class="label_on_time">分</span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="timeType   timeWeekly display_none">
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">星期：</span>
                        <div class="col-xs-6 toggle_form_show">
                            <select class="bs-select form-control" name="free">
                                <option>星期天</option>
                                <option>星期一</option>
                                <option>星期二</option>
                                <option>星期三</option>
                                <option>星期四</option>
                                <option>星期五</option>
                                <option>星期六</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">时间：</span>
                        <div class="col-xs-8">
                            <div class="col-xs-5 paddingZero">
                                <input class="touchspin_2 " type="text" value="" name="demo_vertical567" required max="23">
                            </div>
                            <span class="label_on_time">时</span>
                            <div class="col-xs-5 col-xs-offset-1 paddingZero">
                                <input class="touchspin_3 col-xs-6" type="text" value="" name="demo_vertical678" required max="59">
                            </div>
                            <span class="label_on_time">分</span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="timeType  timeMonth display_none">
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">每月第几天：</span>
                        <div class="col-xs-8">
                            <input class="touchspin_1" type="text" value="" name="demo_vertical789" required min="1" max="31"></div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <div class="row">
                        <span class="col-xs-2 col-xs-offset-1 label_on_l">时间：</span>
                        <div class="col-xs-8">
                            <div class="col-xs-5 paddingZero">
                                <input class="touchspin_2 " type="text" value="" name="demo_vertical108" required max="23">
                            </div>
                            <span class="label_on_time">时</span>
                            <div class="col-xs-5 col-xs-offset-1 paddingZero">
                                <input class="touchspin_3 col-xs-6" type="text" value="" name="demo_vertical2" required max="59">
                            </div>
                            <span class="label_on_time">分</span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group clearfix">
                <div class="col-xs-offset-7 col-xs-4">
                    <button class="btn default fr cancelTime" style="margin-left: 10px;width: 80px;">删除</button>
                    <button class="btn blue-hoki fr saveTime" data-saveSort="0"  style="width: 80px;">保存</button>
                </div>
            </div>
        </form>

    </div>`;

        var subRequencyType = 1,
            subData = {},   //子页面时间类型请求的data数据
            subHour,              //小时
            subMinutes,            //分钟
            subWeekday,            //周
            subDayOfMonth,          // 一个月第几天
            subIntervalMinutes,        //时间间隔分钟
            subIntervalSeconds,      //时间间隔秒
            subFromTime,            //起始时间
            subToTime,              //中止时间
            validator,               //验证参数（boolean）
            validateNum = 0,           //验证的某个时间段
            tuId = window.parent.taskId;

        //验证时间范围封装
        jQuery.validator.methods.compareDate = function(value, element, param) {
            //var startDate = jQuery(param).val() + ":00";补全yyyy-MM-dd HH:mm:ss格式
            //value = value + ":00";

            var startDate = jQuery(param).val();


            var date1 = new Date(Date.parse(startDate.replace(/[&\|\\\*^%$#:@\-]/g, "")));
            var date2 = new Date(Date.parse(value.replace(/[&\|\\\*^%$#:@\-]/g, "")));

            if(startDate === "" && value === ""){
                return true
            }else{
                return date1 < date2;
            }
        };
        //验证提示初始化
        jQuery.extend(jQuery.validator.messages, {
            required: "必填选项",
            remote: "请修正该字段",
            email: "请输入正确格式的电子邮件",
            url: "请输入合法的网址",
            date: "请输入合法的日期",
            dateISO: "请输入合法的日期 (ISO).",
            number: "请输入合法的数字",
            digits: "只能输入整数",
            creditcard: "请输入合法的信用卡号",
            equalTo: "请再次输入相同的值",
            accept: "请输入拥有合法后缀名的字符串",
            maxlength: jQuery.validator.format("请输入一个 长度最多是 {0} 的字符串"),
            minlength: jQuery.validator.format("请输入一个 长度最少是 {0} 的字符串"),
            rangelength: jQuery.validator.format("请输入 一个长度介于 {0} 和 {1} 之间的字符串"),
            range: jQuery.validator.format("请输入一个介于 {0} 和 {1} 之间的值"),
            max: jQuery.validator.format("请输入一个最大为{0} 的值"),
            min: jQuery.validator.format("请输入一个最小为{0} 的值")
        });
        //layui时间范围控件
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            laydate.render({
                elem: '.time1'
                ,type: 'time'
            });

            laydate.render({
                elem: '.time2'
                ,type: 'time'
            });


        });
        //开启验证
        $(".myForm").validate({
            debug:true,
            rules:{
                "timeEnd": {
                    compareDate: ".timeStart"
                }
            },
            messages:{
                "timeStart":{
                    required: "开始时间不能为空（或没有时间段）"
                },
                "timeEnd":{
                    required: "结束时间不能为空（或没有时间段）",
                    compareDate: "结束日期必须大于开始日期!"
                }
            },
        });

        //初始化调度时间页面
        $.ajax({
            url : parent.base + '/rest/ts/findScheTime',
            type : 'GET',
            dataType : 'JSON',
            data : {tuId :tuId },
            success : function(result){
            //    console.log(result.data);
                $('.contentPadding').removeClass('display_none');   //页面显示
                if (result.data.length > 0){        //如果有数据（保存过）
                    $('.addTimeBox').removeClass('display_none');  //添加按钮显示
                    $('.dispatchTime').remove();                    //调度时间删除

                    $.each(result.data,function(i,v){   //遍历数据
                        if(v.requencyType == 2) {
                            //功能初始化
                            addRunTime();
                            formInit('timeEveryday',i,2);
                            //数据初始化
                            $($('.dispatchTime')[i]).find('.timeEveryday  .touchspin_2').val(v.hour);
                            $($('.dispatchTime')[i]).find('.timeEveryday  .touchspin_3').val(v.minutes);

                        }
                        else if(v.requencyType == 3){
                            //功能初始化
                            addRunTime();
                            formInit('timeWeekly',i,3);
                            //数据初始化
                            $($('.dispatchTime')[i]).find('.timeWeekly  .bs-select').val(getDay(v.weekday));
                            $($('.dispatchTime')[i]).find('.timeWeekly  .bs-select').selectpicker('render');
                            $($('.dispatchTime')[i]).find('.timeWeekly  .touchspin_2').val(v.hour);
                            $($('.dispatchTime')[i]).find('.timeWeekly  .touchspin_3').val(v.minutes);
                        }
                        else if (v.requencyType == 4){
                            //功能初始化
                            addRunTime();
                            formInit('timeMonth',i,4);
                            //数据初始化
                            $($('.dispatchTime')[i]).find('.timeMonth  .touchspin_1').val(v.dayOfMonth);
                            $($('.dispatchTime')[i]).find('.timeMonth  .touchspin_2').val(v.hour);
                            $($('.dispatchTime')[i]).find('.timeMonth  .touchspin_3').val(v.minutes);
                        }
                        else if (v.requencyType == 1){
                            //功能初始化
                            addRunTime();
                            formInit('timeInterval',i,1);
                            //数据初始化
                            $($('.dispatchTime')[i]).find('.timeInterval  .touchspin_3')[0].value =  v.intervalSeconds;
                            $($('.dispatchTime')[i]).find('.timeInterval  .touchspin_3')[1].value = v.intervalMinutes;
                            $($('.dispatchTime')[i]).find('.timeInterval  .time1').val(v.fromTime);
                            $($('.dispatchTime')[i]).find('.timeInterval  .time2').val(v.toTime);
                        }

                        $($('.dispatchTime')[i]).attr('hasId',v.tufId); //调度时间添加tufid

                    });


                }
            }
        });

        //点击添加时间点
        $('.addTime').click(function(){
            addRunTime();
        });

        //点击保存或删除按钮
        $('.contentPadding').on('click','.btn',function(){
            var that = $(this);
            var tufId = that.parents('.dispatchTime').attr('hasId');    //调度时间的tufid
            if($(this).hasClass('saveTime')){   //保存按钮事件

                //获取时间类型
                subRequencyType =  requencyTypeToNum($(this).parents('.form-group').siblings('.runTimeType').find('.dropdown-toggle')[0].title);


                if (subRequencyType == 2){

                    subHour = $(this).parents('.form-group').siblings('.timeEveryday').find('.touchspin_2').val();
                    subMinutes = $(this).parents('.form-group').siblings('.timeEveryday').find('.touchspin_3').val();

                    subData = {'tuId':tuId,'requencyType':2 ,'hour':subHour,'minutes':subMinutes}

                }else if(subRequencyType == 3){

                    subWeekday = getWeek($(this).parents('.form-group').siblings('.timeWeekly').find('.dropdown-toggle')[0].title);
                    subHour = $(this).parents('.form-group').siblings('.timeWeekly').find('.touchspin_2').val();
                    subMinutes = $(this).parents('.form-group').siblings('.timeWeekly').find('.touchspin_3').val();

                    subData = {'tuId':tuId,'requencyType':3,'weekday':subWeekday ,'hour':subHour,'minutes':subMinutes}
                }else if(subRequencyType == 4){

                    subDayOfMonth =  $(this).parents('.form-group').siblings('.timeMonth').find('.touchspin_1').val();
                    subHour =  $(this).parents('.form-group').siblings('.timeMonth').find('.touchspin_2').val();
                    subMinutes =  $(this).parents('.form-group').siblings('.timeMonth').find('.touchspin_3').val();

                    subData = {'tuId':tuId,'requencyType':4,'dayOfMonth':subDayOfMonth ,'hour':subHour,'minutes':subMinutes}
                }else if(subRequencyType == 1){

                    subIntervalSeconds = $(this).parents('.form-group').siblings('.timeInterval').find('.touchspin_3')[0].value;
                    subIntervalMinutes = $(this).parents('.form-group').siblings('.timeInterval').find('.touchspin_3')[1].value;
                    subFromTime = $(this).parents('.form-group').siblings('.timeInterval').find('.time1').val();
                    subToTime = $(this).parents('.form-group').siblings('.timeInterval').find('.time2').val();

                    if(subFromTime || subToTime){
                     //   console.log($(this).parents('.form-group').siblings('.timeInterval').find('.time2'));
                        $(this).parents('.form-group').siblings('.timeInterval').find('.time1').attr('required',true);
                        $(this).parents('.form-group').siblings('.timeInterval').find('.time2').attr('required',true);

                    }else{
                        $(this).parents('.form-group').siblings('.timeInterval').find('.time1').attr('required',false);
                        $(this).parents('.form-group').siblings('.timeInterval').find('.time2').attr('required',false);

                    }
                    subData = {'tuId':tuId,'requencyType':1,'intervalMinutes':subIntervalMinutes,'intervalSeconds':subIntervalSeconds,"fromTime":subFromTime,'toTime':subToTime}
                }

              //  console.log($(this).attr('data-saveSort'));
                validateNum = parseInt($(this).attr('data-saveSort')); //验证的第几个表单
                formValidator(validateNum); //验证表单

                console.log(validator);

                if(validator){      //如果验证通过
                    $(this).prev().removeClass('display_none'); //删除按钮显示
                    $('.addTimeBox').removeClass('display_none'); //添加按钮显示
                    $('.newOneTime').remove();                   //'新增'删除

                    if(tufId){  //是否有tufid(是否保存过)
                        subData.tufId = tufId;
                    }
                    console.log(subData);
                    $.ajax({
                        url : parent.base + '/rest/ts/saveScheTime',
                        type : 'GET',
                        dataType : 'JSON',
                        data : subData,
                        success : function(data){
                            console.log(data);
                            console.log(that.parents('.dispatchTime').attr('hasId',data.msg))
                        }
                    });
                }


            }
            else if($(this).hasClass('cancelTime')){    //删除按钮事件
                $(this).parents('.dispatchTime').remove();  //移除当前时间点
                ChineseCountSort();

                if(tufId){
                    $.ajax({
                        url : parent.base + '/rest/ts/deleteScheTime',
                        type : 'GET',
                        dataType : 'JSON',
                        data : {'tufId':tufId},
                        success : function (data) {
                            console.log(data)
                        }
                    })
                }

            }
        });

        //选择时间类型，显示对应的div
        $(document).on('click','div[role="combobox"]',function(){
        //    console.log($(this).prev('button').attr('title'));
            var message = $(this).prev('button').attr('title'); //

            $(this).parents('.form-group').siblings('.timeType').addClass('display_none');
            if(message == '按时间间隔'){
                $(this).parents('.form-group').siblings('.timeInterval').removeClass('display_none');
                subRequencyType = 1;
            }else if(message == '按天'){
                $(this).parents('.form-group').siblings('.timeEveryday').removeClass('display_none');
                subRequencyType = 2;
            }else if(message == '按周'){
                $(this).parents('.form-group').siblings('.timeWeekly').removeClass('display_none');
                subRequencyType = 3;
            }else if(message == '按月'){
                $(this).parents('.form-group').siblings('.timeMonth').removeClass('display_none');
                subRequencyType = 4;

            }
        });

        //中文数字排序
        function ChineseCountSort(){
            var count =1,saveCount=0;
            $.each($('.dispatchTime .chineseCount'),function (i, v) {
                $(this).text(SectionToChinese(count));
                count++;
            });

            $.each($('.dispatchTime .saveTime'),function(){
                $(this).attr('data-saveSort',saveCount);
                saveCount++;
            })
        }


        var chnNumChar = ["零","一","二","三","四","五","六","七","八","九"];
        var chnUnitSection = ["","万","亿","万亿","亿亿"];
        var chnUnitChar = ["","十","百","千"];

        //阿拉伯数字转中文数字
        function SectionToChinese(section){
            var strIns = '', chnStr = '';
            var unitPos = 0;
            var zero = true;
            while(section > 0){
                var v = section % 10;
                if(v === 0){
                    if(!zero){
                        zero = true;
                        chnStr = chnNumChar[v] + chnStr;
                    }
                }else{
                    zero = false;
                    strIns = chnNumChar[v];
                    strIns += chnUnitChar[unitPos];
                    chnStr = strIns + chnStr;
                }
                unitPos++;
                section = Math.floor(section / 10);
            }
            return chnStr;
        }

        //添加调度时间封装
        function addRunTime(){
            //添加调度时间
            $('.contentPadding').append(dispatchTimeHtml);

            //当前调度时间功能初始化
            $(".touchspin_1").TouchSpin({verticalbuttons: !0,min : 1, max: 31}), $(".touchspin_2").TouchSpin({verticalbuttons: !0, max: 23}), $(".touchspin_3").TouchSpin({verticalbuttons: !0, max: 59});
            $(".bs-select").selectpicker({iconBase: "fa", tickIcon: "fa-check"});
            ChineseCountSort();
            $.each($('.dispatchTime'),function(i,v){
                layui.use('laydate', function(){
                    var laydate = layui.laydate;

                    laydate.render({
                        elem: document.getElementsByClassName('time1')[i]
                        ,type: 'time'
                    });

                    laydate.render({
                        elem: document.getElementsByClassName('time2')[i]
                        ,type: 'time'
                    });
                });
             //   console.log($($(".myForm")[i]));
                $($(".myForm")[i]).validate({
                    debug:true,
                    rules:{
                        "timeEnd": {
                            compareDate: document.getElementsByClassName('time1')[i]
                        }
                    },
                    messages:{
                        "timeStart":{
                            required: "开始时间不能为空（或没有时间段）"
                        },
                        "timeEnd":{
                            required: "结束时间不能为空（或没有时间段）",
                            compareDate: "结束日期必须大于开始日期!"
                        }
                    },
                });

             /*   $(".myForm").validate({
                    debug:true,
                    rules:{
                        "timeEnd": {
                            compareDate: document.getElementsByClassName('timeStart')[i]
                        }
                    },
                    messages:{
                        "timeStart":{
                            required: "开始时间不能为空（或没有时间段）"
                        },
                        "timeEnd":{
                            required: "结束时间不能为空（或没有时间段）",
                            compareDate: "结束日期必须大于开始日期!"
                        }
                    },
                });*/
            });

        }

        //数字转每周几
        function getDay(num){
            return '星期' + ['','天','一','二','三','四','五','六'][num];
        }

        //周几转数字
        function getWeek(val){
           var arr1 = ['星期天','星期一','星期二','星期三','星期四','星期五','星期六'];
           var arr2 =  [1,2,3,4,5,6,7];
          var index = arr1.indexOf(val);
           return arr2[index];
        }

        //调度类型对应数字
        function requencyTypeToNum(val){
            var arr1 = ['按时间间隔','按天','按周','按月'];
            var arr2 = [1,2,3,4];
            var index = arr1.indexOf(val);
           return arr2[index];
        }

        //文字转调度时间
        function numToRequencyType(num){
            return   ['','按时间间隔','按天','按周','按月'][num];
        }

        //调度时间表单初始化
        function formInit(timeEveryday,i,requencyType){
            $($('.dispatchTime')[i]).find('.timeType').addClass('display_none'); //所有timeType隐藏
            $($('.dispatchTime')[i]).find('.'+timeEveryday).removeClass('display_none'); //当前timeType显示
            $($('.dispatchTime')[i]).find('.runTimeType  .bs-select').val(numToRequencyType(requencyType)); //显示当前调度类型
            $($('.dispatchTime')[i]).find('.runTimeType  .bs-select').selectpicker('render');       //更新当前调度类型
        }

        //验证表单返回true or false
        function formValidator(i){
            validator = $($(".myForm")[i]).valid();
        //    console.log(validator);
            return validator;
        }
    })


</script>
</html>